﻿using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace HindernisGame
{
    class HighscoreScreen
    {
        private Game1 game;
        private SpriteBatch spriteBatch;
        private Rectangle mainFrame;
        private int sperre = 20;
        private KeyboardState currentState;
        private menuButton zurueckB;
        private menuButton highscoreB;
        private List<menuButton> mbs = new List<menuButton>();

        public HighscoreScreen(Game1 game)
        {
            this.game = game;
            zurueckB = new menuButton(new Rectangle(100, 620, 162, 36), game.Content.Load<Texture2D>("menu/Zurueck"), 0, true);
            highscoreB = new menuButton(new Rectangle(100, 220, 372, 72), game.Content.Load<Texture2D>("menu/Highscore"), 1, false);

            mbs.Add(zurueckB);
            mbs.Add(highscoreB);
        }

        public void LoadContent()
        {
            spriteBatch = new SpriteBatch(game.GraphicsDevice);
            mainFrame = new Rectangle(0, 0, game.GraphicsDevice.Viewport.Width, game.GraphicsDevice.Viewport.Height);
            loadScores();
        }

        public void loadScores()
        {
            game.highscore = game.highscoreStruct.LoadHighScores("hs.dat");
        }

        public void Update()
        {
            if (sperre > 0)
                sperre--;
            else
            {
                currentState = Keyboard.GetState();

                if (currentState.IsKeyDown(Keys.Enter))
                {
                     sperre = 15;
                     game.setCurrentScreen("startScreen");
                }
            }
        }

        public void Draw()
        {
            spriteBatch.Begin();
            spriteBatch.Draw(game.background, mainFrame, Color.White);
            spriteBatch.Draw(game.logo, new Rectangle(100, -50, 824, 291), new Color(255, 255, 255, 255));
            //Highscores

            for (int i = 0; i < game.highscore.Count; i++)
            {
                if (i > 9)
                    break;
                spriteBatch.DrawString(game.font, game.highscore.PlayerName[i], new Vector2(620, 220 + i * 50), Color.White);
                spriteBatch.DrawString(game.font, game.highscore.Score[i].ToString(), new Vector2(800, 220 + i * 50), Color.White);
            }

            zurueckB.Draw(spriteBatch, game.font);
            highscoreB.Draw(spriteBatch, game.font);
            spriteBatch.End();
        }
    }
}